package com.design.pattern.command.after;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * 长沙先飞信息科技有限公司<br>
 * Created with IntelliJ IDEA.<br>
 * Date:2024/6/20<br>
 * Time:16:44<br>
 * 功能描述：<br>
 *      服务员类：只负责记录菜单，然后通知 “烤肉串者” 执行即可
 * @author huang hou chun
 * @since JDK 1.8 <br>
 * Copyright (c) 2023 www.csxfrj.com System Incorporated All Rights Reserved.
 */
public class Waiter {

    private final Queue<Command> commands = new LinkedList<>();

    // 设置订单
    public void setOrder(Command command) {
        if (command.toString().equals("烤鸡翅")) {
            System.out.println("服务员：鸡翅没有了，请点别的烧烤");
        } else {
            commands.offer(command);
            System.out.println("增加订单：" + command + " 时间：" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
    }

    // 通知执行
    public void notifyExecute() {
        Iterator<Command> it = commands.iterator();
        while (it.hasNext()) {
            it.next().execute();
            it.remove();
        }
    }
}
